package com.we823.project.repository.service.sys;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.we823.project.model.RoleModel;
import com.we823.project.repository.dao.RoleRepository;
import com.we823.project.repository.service.AbstractBaseService;

@Service("roleService")
public class RoleService extends AbstractBaseService<RoleModel> {

	private RoleRepository roleRepository;
	
	@Autowired
	public RoleService(RoleRepository roleRepository) {
		super(roleRepository);
		this.roleRepository = roleRepository;
	}

	public Map<Integer, RoleModel> map() {
		List<RoleModel> roleModels = findAll();
		if(roleModels!=null) {
			Map<Integer, RoleModel> map = new HashMap<Integer, RoleModel>();
			for (RoleModel roleModel : roleModels) {
				map.put(roleModel.getId(), roleModel);
			}
			return map;
		}
		return null;
	}
	
	public Set<String> findRolesByRoleidIn(List<Integer> roleidList){
		Set<String> roleSet = new HashSet<>();
		List<RoleModel> roleModels = findByIdIn(roleidList);
		if(roleModels!=null) {
			for (RoleModel roleModel : roleModels) {
				roleSet.add(roleModel.getIdentity());
			}
		}
		return roleSet;
	}

	public List<RoleModel> findByIdIn(List<Integer> roleidList) {
		return roleRepository.findByIdIn(roleidList);
	}

}
